package com.example.demo.controller;

import cn.hutool.core.util.EnumUtil;
import com.example.demo.entity.User;
import com.example.demo.strategy.HandleStrategy;
import com.example.demo.strategy.StrategyEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Optional;

/**
 * @author 江黎
 * @since 2022-11-17
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class TestController {
    private final Map<String, HandleStrategy> handleStrategyMap;

    @PostMapping
    public void test(@RequestBody User user) {
        for (Map.Entry<String, HandleStrategy> entry : handleStrategyMap.entrySet()) {
            System.out.println("clazz = " + entry.getKey() + " , Class = " + entry.getValue());
        }
        StrategyEnum strategyEnum = EnumUtil.likeValueOf(StrategyEnum.class, user.getType());
        handleStrategyMap.get(strategyEnum.getClazz()).handle(user);
    }
}
